package com.yun.util.yun.utils;
import org.apache.commons.collections.CollectionUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
import java.util.stream.IntStream;


public final class UUIDUtil {

	/**
	 * 随机生成uuid
	 * 
	 * @return
	 */
	public static String getUUID() {
		return UUID.randomUUID().toString().replace("-", "");
	}


    /**
     * 集合分割
     * @param list
     * @param size
     * @param <T>
     * @return
     */
    public static <T> List<List<T>> partList(List<T> list, int size) {
        if (CollectionUtils.isEmpty(list) || size < 1) {
            return new ArrayList<>();
        }

        List<List<T>> partList = IntStream.range(0, list.size())
                .boxed()
                .collect(Collectors.groupingBy(index -> index / size))
                .values()
                .stream()
                .map(indices -> indices.stream().map(list::get).collect(Collectors.toList()))
                .collect(Collectors.toList());

        return partList;
    }
}